﻿#define _CRT_SECURE_NO_WARNINGS 1
#include <stdio.h>

int findkey(int arr[][3], int r, int c, int key)
{
	int i = 0, j = c-1;
	while (i < r && j >= 0)
	{
		if (arr[i][j] < key)
		{
			i++;
		}
		else if (arr[i][j] == key)
		{
			return 1;
		}
		else
		{
			j--;
		}
	}
	return 0;
}

int main()
{
	int arr[3][3] = {1,2,3,5,8,9,11,23,45};//假设有这样一个杨氏矩阵，3*3，从左到右、从上到下递增
	//查找矩阵中的某个元素,比如8
	int key = 8;
	int re = findkey(arr, 3, 3, key);
	if (re == 1)
	{
		printf("该数存在于数组中。\n");
	}
	else
	{
		printf("数组中无此数。\n");
	}

	return 0;
}